/**
 * @author yusak
 */
ChaShaKu.AdvancedSearchPanel = Ext.extend(Ext.app.Module,{
	id: "advancedSearchPanel",
	init: function(){
		this.onReady = false;
	},
	run: function(){
		this.app.modules.searchMenuButtons.advanced.setHandler(this.show,this);
	},
	show: function(){
		if(!this.onReady){
			this.dialog = this.create();
			this.beforeRenderModules.each(function(m,index){
				m.create();
			});
			this.dialog.show();
			this.afterRenderedModules.each(function(m,index){
				m.create();
			});
			this.onReady = true;
		}else{
			this.dialog.show();	
		}		
	},
	create: function(){
		var ds = Ext.app.Data.WordPropertyStore.create();
		this.grid = Ext.app.Grid.WordPropertyGrid.create(ds);
		return new Ext.Window({
	        title:'Advanced Search',
	        width:800,
			height:350,
	        minWidth:500,
			minHeight:200,
            layout:'fit',
			autoDestroy: true,
			closeAction:'hide',
			modal:true,
			shim:false,
            animCollapse:false,
            constrainHeader:true,
			animateTarget:this.app.modules.searchMenuButtons.advanced.getEl(),
	        bodyStyle:'padding:5px;',
			buttonAlign:'right',
	        items: this.grid,
	        listeners: {
	    			hide:function(){
	    				if(ds.getCount() < 1){
	    					this.onReady = false;
	    				}
	    			},
	    			scope: this.app.modules.advancedSearchPanel
	    		}
	    });
	},
	beforeRenderModules: [],
	afterRenderedModules: [],
	searchBtns:[]
});
